package com.zdj.question;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * @author zhangdj
 * @date 2022-08-26
 * 年月日之和
 */
public class QuestionTest {

    public static void main(String[] args) {
//        String s = args[0];
        solution("50-01-01");
    }

    public static void solution(String dateStr) {
        if (!dateStr.contains("-")) {
            System.out.print("格式有误");
        }
        String[] split = dateStr.split("-");
        List<String> list = Arrays.asList(split);
        Optional<Integer> optional = list.stream().map(Integer::valueOf).reduce(Integer::sum);
        if (optional.isPresent()) {
            Integer result = optional.get();
            // 判断是否是闰年
            int year = Integer.parseInt(split[0]);
            if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
                System.out.print(result * 2);
            } else {
                System.out.print(result);
            }
        }
    }
}
